package top.itmeans.yes.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.itmeans.yes.common.api.CommonResult;
import top.itmeans.yes.api.CommonPage;
import top.itmeans.yes.entity.Subject;
import top.itmeans.yes.service.SubjectService;

import java.util.List;

/**
 * <p>
 * 专题表 前端控制器  CMS
 * </p>
 *
 * @author Yiming.Cao
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/subject")
public class SubjectController {
    @Autowired
    private SubjectService subjectService;

    /**
     * GET [host:ip/serverPath]/subject/list
     */
    @ApiOperation("获取全部商品专题")
    @GetMapping(value = "/listAll")
    public CommonResult<List<Subject>> listAll() {
        List<Subject> subjectList = subjectService.list();
        return CommonResult.success(subjectList);
    }

    /**
     * GET [host:ip/serverPath]/subject/list/{keyword}
     */
    @ApiOperation(value = "根据专题名称分页获取专题")
    @GetMapping(value = "/list/{keyword}")
    public CommonResult<CommonPage<Subject>> getList(@PathVariable String keyword,
                                                     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                     @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        Page<Subject> subjectPage = subjectService.page(keyword, pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(subjectPage));
    }
}
